//
//  NSString+YJMIME.m
//  YJCategoriesGather
//
//  Created by YJHou on 2014/11/4.
//  Copyright © 2014年 侯跃军 houmanager@Hotmail.com. All rights reserved.
//

#import "NSString+YJMIME.h"

@implementation NSString (YJMIME)

/** 根据文件url后缀 返回对应的MIMEType */
- (NSString *)yj_MIMEType{
    return [[self class] yj_MIMETypeForExtension:[self pathExtension]];
}

/** 根据扩展返回 MIMEType */
+ (NSString *)yj_MIMETypeForExtension:(NSString *)extension{
    return [[self yj_MIMEDict] valueForKey:[extension lowercaseString]];
}

/** 常见MIME集合 */
+ (NSDictionary *)yj_MIMEDict{
    NSDictionary * MIMEDict;
    // Lazy loads the MIME type dictionary.
    if (!MIMEDict) {
        // ???: Should I have these return an array of MIME types? The first element would be the preferred MIME type.
        
        // ???: Should I have a couple methods that return the MIME media type name and the MIME subtype name?
        
        // Values from http://www.w3schools.com/media/media_mimeref.asp
        // There are probably values missed, but this is a good start.
        // A few more have been added that weren't included on the original list.
        MIMEDict = [NSDictionary dictionaryWithObjectsAndKeys:
                    // Key                         // Value
                    @"application/octet-stream",    @"",
                    @"text/h323",    @"323",
                    @"application/internet-property-stream",    @"acx",
                    @"application/postscript",    @"ai",
                    @"audio/x-aiff",    @"aif",
                    @"audio/x-aiff",    @"aifc",
                    @"audio/x-aiff",    @"aiff",
                    @"video/x-ms-asf",    @"asf",
                    @"video/x-ms-asf",    @"asr",
                    @"video/x-ms-asf",    @"asx",
                    @"audio/basic",    @"au",
                    @"video/x-msvideo",    @"avi",
                    @"application/olescript",    @"axs",
                    @"text/plain",    @"bas",
                    @"application/x-bcpio",    @"bcpio",
                    @"application/octet-stream",    @"bin",
                    @"image/bmp",    @"bmp",
                    @"text/plain",    @"c",
                    @"application/vnd.ms-pkiseccat",    @"cat",
                    @"application/x-cdf",    @"cdf",
                    @"application/x-x509-ca-cert",    @"cer",
                    @"application/octet-stream",    @"class",
                    @"application/x-msclip",    @"clp",
                    @"image/x-cmx",    @"cmx",
                    @"image/cis-cod",    @"cod",
                    @"application/x-cpio",    @"cpio",
                    @"application/x-mscardfile",    @"crd",
                    @"application/pkix-crl",    @"crl",
                    @"application/x-x509-ca-cert",    @"crt",
                    @"application/x-csh",    @"csh",
                    @"text/css",    @"css",
                    @"application/x-director",    @"dcr",
                    @"application/x-x509-ca-cert",    @"der",
                    @"application/x-director",    @"dir",
                    @"application/x-msdownload",    @"dll",
                    @"application/octet-stream",    @"dms",
                    @"application/msword",    @"doc",
                    @"application/vnd.openxmlformats-officedocument.wordprocessingml.document",    @"docx",
                    @"application/msword",    @"dot",
                    @"application/x-dvi",    @"dvi",
                    @"application/x-director",    @"dxr",
                    @"application/postscript",    @"eps",
                    @"text/x-setext",    @"etx",
                    @"application/envoy",    @"evy",
                    @"application/octet-stream",    @"exe",
                    @"application/fractals",    @"fif",
                    @"x-world/x-vrml",    @"flr",
                    @"image/gif",    @"gif",
                    @"application/x-gtar",    @"gtar",
                    @"application/x-gzip",    @"gz",
                    @"text/plain",    @"h",
                    @"application/x-hdf",    @"hdf",
                    @"application/winhlp",    @"hlp",
                    @"application/mac-binhex40",    @"hqx",
                    @"application/hta",    @"hta",
                    @"text/x-component",    @"htc",
                    @"text/html",    @"htm",
                    @"text/html",    @"html",
                    @"text/webviewhtml",    @"htt",
                    @"image/x-icon",    @"ico",
                    @"image/ief",    @"ief",
                    @"application/x-iphone",    @"iii",
                    @"application/x-internet-signup",    @"ins",
                    @"application/x-internet-signup",    @"isp",
                    @"image/pipeg",    @"jfif",
                    @"image/jpeg",    @"jpe",
                    @"image/jpeg",    @"jpeg",
                    @"image/jpeg",    @"jpg",
                    @"application/x-javascript",    @"js",
                    @"application/json",    @"json",
                    @"application/x-latex",    @"latex",
                    @"application/octet-stream",    @"lha",
                    @"video/x-la-asf",    @"lsf",
                    @"video/x-la-asf",    @"lsx",
                    @"application/octet-stream",    @"lzh",
                    @"text/plain",    @"m",
                    @"application/x-msmediaview",    @"m13",
                    @"application/x-msmediaview",    @"m14",
                    @"audio/x-mpegurl",    @"m3u",
                    @"application/x-troff-man",    @"man",
                    @"application/x-msaccess",    @"mdb",
                    @"application/x-troff-me",    @"me",
                    @"message/rfc822",    @"mht",
                    @"message/rfc822",    @"mhtml",
                    @"audio/mid",    @"mid",
                    @"application/x-msmoney",    @"mny",
                    @"video/quicktime",    @"mov",
                    @"video/x-sgi-movie",    @"movie",
                    @"video/mpeg",    @"mp2",
                    @"audio/mpeg",    @"mp3",
                    @"video/mpeg",    @"mpa",
                    @"video/mpeg",    @"mpe",
                    @"video/mpeg",    @"mpeg",
                    @"video/mpeg",    @"mpg",
                    @"application/vnd.ms-project",    @"mpp",
                    @"video/mpeg",    @"mpv2",
                    @"application/x-troff-ms",    @"ms",
                    @"	application/x-msmediaview",    @"mvb",
                    @"message/rfc822",    @"nws",
                    @"application/oda",    @"oda",
                    @"application/pkcs10",    @"p10",
                    @"application/x-pkcs12",    @"p12",
                    @"application/x-pkcs7-certificates",    @"p7b",
                    @"application/x-pkcs7-mime",    @"p7c",
                    @"application/x-pkcs7-mime",    @"p7m",
                    @"application/x-pkcs7-certreqresp",    @"p7r",
                    @"	application/x-pkcs7-signature",    @"p7s",
                    @"image/x-portable-bitmap",    @"pbm",
                    @"application/pdf",    @"pdf",
                    @"application/x-pkcs12",    @"pfx",
                    @"image/x-portable-graymap",    @"pgm",
                    @"application/ynd.ms-pkipko",    @"pko",
                    @"application/x-perfmon",    @"pma",
                    @"application/x-perfmon",    @"pmc",
                    @"application/x-perfmon",    @"pml",
                    @"application/x-perfmon",    @"pmr",
                    @"application/x-perfmon",    @"pmw",
                    @"image/png",    @"png",
                    @"image/x-portable-anymap",    @"pnm",
                    @"application/vnd.ms-powerpoint",    @"pot",
                    @"image/x-portable-pixmap",    @"vppm",
                    @"application/vnd.ms-powerpoint",    @"pps",
                    @"application/vnd.ms-powerpoint",    @"ppt",
                    @"application/vnd.openxmlformats-officedocument.presentationml.presentation",    @"pptx",
                    @"application/pics-rules",    @"prf",
                    @"application/postscript",    @"ps",
                    @"application/x-mspublisher",    @"pub",
                    @"video/quicktime",    @"qt",
                    @"audio/x-pn-realaudio",    @"ra",
                    @"audio/x-pn-realaudio",    @"ram",
                    @"image/x-cmu-raster",    @"ras",
                    @"image/x-rgb",    @"rgb",
                    @"audio/mid",    @"rmi",
                    @"application/x-troff",    @"roff",
                    @"application/rtf",    @"rtf",
                    @"text/richtext",    @"rtx",
                    @"application/x-msschedule",    @"scd",
                    @"text/scriptlet",    @"sct",
                    @"application/set-payment-initiation",    @"setpay",
                    @"application/set-registration-initiation",    @"setreg",
                    @"application/x-sh",    @"sh",
                    @"application/x-shar",    @"shar",
                    @"application/x-stuffit",    @"sit",
                    @"audio/basic",    @"snd",
                    @"application/x-pkcs7-certificates",    @"spc",
                    @"application/futuresplash",    @"spl",
                    @"application/x-wais-source",    @"src",
                    @"application/vnd.ms-pkicertstore",    @"sst",
                    @"application/vnd.ms-pkistl",    @"stl",
                    @"text/html",    @"stm",
                    @"image/svg+xml",    @"svg",
                    @"application/x-sv4cpio",    @"sv4cpio",
                    @"application/x-sv4crc",    @"sv4crc",
                    @"application/x-shockwave-flash",    @"swf",
                    @"application/x-troff",    @"t",
                    @"application/x-tar",    @"tar",
                    @"application/x-tcl",    @"tcl",
                    @"application/x-tex",    @"tex",
                    @"application/x-texinfo",    @"texi",
                    @"application/x-texinfo",    @"texinfo",
                    @"application/x-compressed",    @"tgz",
                    @"image/tiff",    @"tif",
                    @"image/tiff",    @"tiff",
                    @"application/x-troff",    @"tr",
                    @"application/x-msterminal",    @"trm",
                    @"text/tab-separated-values",    @"tsv",
                    @"text/plain",    @"txt",
                    @"text/iuls",    @"uls",
                    @"application/x-ustar",    @"ustar",
                    @"text/x-vcard",    @"vcf",
                    @"x-world/x-vrml",    @"vrml",
                    @"audio/x-wav",    @"wav",
                    @"application/vnd.ms-works",    @"wcm",
                    @"application/vnd.ms-works",    @"wdb",
                    @"application/vnd.ms-works",    @"wks",
                    @"application/x-msmetafile",    @"wmf",
                    @"application/vnd.ms-works",    @"wps",
                    @"application/x-mswrite",    @"wri",
                    @"x-world/x-vrml",    @"wrl",
                    @"x-world/x-vrml",    @"wrz",
                    @"x-world/x-vrml",    @"xaf",
                    @"image/x-xbitmap",    @"xbm",
                    @"application/vnd.ms-excel",    @"xla",
                    @"application/vnd.ms-excel",    @"xlc",
                    @"application/vnd.ms-excel",    @"xlm",
                    @"application/vnd.ms-excel",    @"xls",
                    @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",    @"xlsx",
                    @"application/vnd.ms-excel",    @"xlt",
                    @"application/vnd.ms-excel",    @"xlw",
                    @"text/xml",    @"xml",
                    @"x-world/x-vrml",    @"xof",
                    @"image/x-xpixmap",    @"xpm",
                    @"image/x-xwindowdump",    @"xwd",
                    @"application/x-compress",    @"z",
                    @"application/zip",    @"zip",
                    nil];
    }
    
    return MIMEDict;
}

@end
